home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_02 / cutil / comext.c < prev    next >
C/C++ Source or Header  |  1994-03-20  |  806b  |  42 lines

  1. /*
  2.  * Simple filter to extract comments from a 'C' source file
  3.  *
  4.  * Compile command: cc comext -fop
  5.  */
  6. #include <stdio.h>
  7.  
  8. int readch()
  9. {
  10.     int c;
  11.  
  12.     if((c = getc(stdin)) == EOF)
  13.         exit(0);
  14.     return c;
  15. }
  16.  
  17. main()
  18. {
  19.     int c, c1;
  20.  
  21.     c = 0;        /* Fake a non-special character value to kick-start */
  22.     for(;;) {
  23.         switch(c) {
  24.             case '/' :                        /* Possible comment */
  25.                 if((c = readch()) != '*')
  26.                     continue;
  27.                 fputs("/*", stdout);
  28.                 c = 0;                        /* Forget '*' */
  29.                 do {
  30.                     c1 = c;
  31.                     putc(c = readch(), stdout); }
  32.                 while((c1 != '*') || (c != '/'));
  33.                 putc('\n', stdout);
  34.                 break;
  35.             case '"' :                        /* Literal string */
  36.             case '\'' :                        /* Character constant */
  37.                 while((c1 = readch()) != c)
  38.                     if(c1 == '\\')
  39.                         readch(); }
  40.         c = readch(); }
  41. }
  42.